package bc.controller;

import bc.model.Cards;

import bc.event.CardClick;

import haxe.rtti.Infos;
import haxe.Timer;

class CardsLayoutController implements Infos
{
	@Inject
	public var cards : Cards;
	
	@Inject
	public var cardsLayoutComputer : CardsLayoutComputer;
	
	public function new()
	{
	}
	
	@Complete
	public function handleComplete()
	{
		cardsLayoutComputer.computeInitialSetup();
		cardsLayoutComputer.computeTargets(); 
		
		var timer = new Timer(Std.int(1000 / 60));
		timer.run = handleTimer;
	}
	
	@MessageHandler
	public function handleCardClick(event : CardClick)
	{
		cards.selected = event.card;
		cardsLayoutComputer.computeTargets(); 
	}
	
	private function handleTimer()
	{
		cardsLayoutComputer.move();
	}	
}
